package com.mvd.app.activity;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.v3.MessageDialog;
import com.kongzue.dialog.v3.WaitDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.ac2020.DiGouActivity;
import com.mvd.app.ac2020.QingDaoPhotoActivity;
import com.mvd.app.ac2021.activitys.CarActivity;
import com.mvd.app.ac2021.activitys.SignActivity;
import com.mvd.app.adapter.CarsInforListAdapter;
import com.mvd.app.adapter.MyAccountModeListAdapter;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.Constants;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.FileUtils;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.CarCheckItemsModel;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.DownLineModel;
import com.mvd.app.upload.MyUploadVideoActivity;
import com.orhanobut.logger.Logger;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @Description: 待检车辆列表
 */
public class DaiJianCarsActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    @BindView(R.id.ac_daijian_et_search2)
    EditText acDaijianEtSearch2;
    @BindView(R.id.ac_daijian_btn_search2)
    Button acDaijianBtnSearch2;
    @BindView(R.id.ac_daijian_bt_type2)
    Button acDaijianBtType2;
    @BindView(R.id.list_shequgonggao_baoxiu)
    ListView listShequgonggaoBaoxiu;
    @BindView(R.id.fab)
    FloatingActionButton fab;
    @BindView(R.id.ac_daijian_btn_chongxin_xiaxian)
    Button acDaijianBtnChongxinXiaxian;
    @BindView(R.id.ac_set_view_m_2_image)
    TextView acSetViewM2Image;
    @BindView(R.id.ac_daijian_btn_buchuan_zhaopian)
    Button acDaijianBtnBuchuanZhaopian;
    @BindView(R.id.ac_daijian_lay_ll_statement)
    LinearLayout acDaijianLayStatament;

    private int CHECK_MODE = 0;//检测模式 0:外检  1：路试 2：底盘动态
    private List<CarsInforModel> carsInforModelList = new ArrayList<CarsInforModel>();
    private List<CarsInforModel> carsInforModelList_2 = new ArrayList<CarsInforModel>();
    private List<CarsInforModel> searChCarsList_one = new ArrayList<CarsInforModel>();//查询的列表
    private List<CarsInforModel> searChCarsList_two = new ArrayList<CarsInforModel>();//查询的列表
    private List<CarsInforModel> searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表

    //adapter的过滤后的数据列表
    private List<CarsInforModel> adapterCarsList = new ArrayList<CarsInforModel>();
    private CarsInforListAdapter carsInforListAdapter;
    public DaiJianCarsActivity instances = null;
    private String carNO = null;
    private List<CarCheckItemsModel> carCheckItemModelList = new ArrayList<CarCheckItemsModel>();
    //待检测车辆要检测的项目的列表
    private String CURRENT_CHECK_MODE = "";//当前检测模式
    private String Login_name = "", login_IDNumber;//当前登录的检测员的名字
    private DownLineModel downLineModel;
    private Handler handler = new Handler();
    MyRunnable myRunnable = new MyRunnable();//定义MyRunnable的对象；

    String sign_url = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dai_jian_cars_2);
        ButterKnife.bind(this);
        setTopTitle(R.string.activity_daijian_car_list);
        setHideLeftBtn();
        instances = this;
        String logStrf = "\n" + "onCreate-----车辆队列-------" + "\n"+
                "大车开关==="+SharedPreferencesUtils.getDaChe(instances)+"\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());

        setRightTxt("录像列表", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(DaiJianCarsActivity.this, MyUploadVideoActivity.class);
                startActivity(i);
            }
        });

        Login_name = getIntent().getExtras().getString("login_UserID", "");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");

        CHECK_MODE = BaseApplication.JIANCE_MODE;
        UtilsLog.e(" BaseApplication.JIANCE_MODE-DaiJianCarsActivity==" + BaseApplication.JIANCE_MODE);
        listShequgonggaoBaoxiu.setOnItemClickListener(this);
        pop_type();

        switch (BaseApplication.JIANCE_MODE) {
            //检测模式 0:外检  F1 1：路试 R1 2：底盘动态 DC
            case 0:
                CURRENT_CHECK_MODE = "F1";
                break;
            case 1:
                CURRENT_CHECK_MODE = "R1";
                break;
            case 2:
                CURRENT_CHECK_MODE = "DC";
                break;
            case 6:
                CURRENT_CHECK_MODE = "C1";
                break;
            case 8:
                CURRENT_CHECK_MODE = "F1";
                break;
        }
        try {
            String filePath = null;
            filePath = Environment.getExternalStorageDirectory() + "/PDASetting/setting.txt";
            String reCheckPhotoSetting = FileUtils.readTextFile(new File(filePath)).trim();
            Log.e("tag", "复检拍照设置==" + reCheckPhotoSetting);
//            if (!TextUtils.isEmpty(reCheckPhotoSetting)) {
//                if (reCheckPhotoSetting.equals("123456")) {
//                    acDaijianBtType2.setVisibility(View.GONE);
//                    Log.e("tag", "复检拍照设置=======隐藏=");
//                } else {
//                    Log.e("tag", "复检拍照设置====11===显示=");
//                    acDaijianBtType2.setVisibility(View.VISIBLE);
//                }
//            } else {
//                Log.e("tag", "复检拍照设置====22===显示=");
//                acDaijianBtType2.setVisibility(View.VISIBLE);
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }


        //重新下线与补传照片的开关显示与隐藏
        if (SharedPreferencesUtils.getChongXinXiaXianStatement(instances) == false &&
                SharedPreferencesUtils.getBuChuanZhaoPianStatement(instances) == false) {
            acDaijianLayStatament.setVisibility(View.GONE);
        } else {
            acDaijianLayStatament.setVisibility(View.VISIBLE);
        }
        Log.e("tag", "重新下线设置==" + SharedPreferencesUtils.getChongXinXiaXianStatement(instances));
        Log.e("tag", "补传照片设置==" + SharedPreferencesUtils.getBuChuanZhaoPianStatement(instances));
        if (SharedPreferencesUtils.getChongXinXiaXianStatement(instances)) {
            acDaijianBtnChongxinXiaxian.setVisibility(View.VISIBLE);
        } else {
            acDaijianBtnChongxinXiaxian.setVisibility(View.GONE);
        }

        if (SharedPreferencesUtils.getBuChuanZhaoPianStatement(instances)) {
            acDaijianBtnBuchuanZhaopian.setVisibility(View.VISIBLE);
        } else {
            acDaijianBtnBuchuanZhaopian.setVisibility(View.GONE);
        }

        //如果缓存的日期为null
        if (SharedPreferencesUtils.getSaveDate(instances) == null) {
            SharedPreferencesUtils.setSaveDate(instances, "");
        }
        //如果缓存的日期不为空
        if (SharedPreferencesUtils.getSaveDate(instances) != null) {
            //如果日期不相等
            if (!SharedPreferencesUtils.getSaveDate(instances).equals(DateUtil.getTodayDate2())) {
                //开启签名功能
                if (SharedPreferencesUtils.getOpenSign(this)) {
                    MessageDialog.show(instances, "提示", "签名", "确定", "取消")
                            .setOkButton(new OnDialogButtonClickListener() {
                                @Override
                                public boolean onClick(BaseDialog baseDialog, View v) {
                                    Intent signIntent = new Intent(DaiJianCarsActivity.this, SignActivity.class);
                                    startActivityForResult(signIntent, 808);
                                    return false;
                                }
                            })
                            .setCancelButton(new OnDialogButtonClickListener() {
                                @Override
                                public boolean onClick(BaseDialog baseDialog, View v) {
                                    return false;
                                }
                            });

                }
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 808:
                sign_url = data.getStringExtra("image");
                if (sign_url != null) {
                    SharedPreferencesUtils.setSaveDate(instances, DateUtil.getTodayDate2());
                }
                break;

        }
    }

    @OnClick({R.id.ac_daijian_btn_search2, R.id.ac_daijian_bt_type2, R.id.fab,
            R.id.ac_daijian_btn_chongxin_xiaxian, R.id.ac_daijian_btn_buchuan_zhaopian})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_daijian_btn_search2:
                //查询
                carNO = acDaijianEtSearch2.getText().toString().trim();
                if (!TextUtils.isEmpty(carNO)) {
                    CommonUtils.showLoadingDialog(instances, "加载中...");
                    downLineModel = new DownLineModel();
                    downLineModel.setType("0");
                    downLineModel.setPlateNO(carNO);
                    searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表
                    for (int i = 0; i < 2; i++) {
                        if (i == 0) {
                            downLineModel.setStatus("0");
                            getDataSearchCarsByNO(downLineModel);
//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//                                    getDataSearchCarsByNO(downLineModel);
//                                }
//                            }, 1000);//后执行Runnable中的run方法

                        } else if (i == 1) {
                            downLineModel.setStatus("1");
                            getDataSearchCarsByNO(downLineModel);
//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//                                    getDataSearchCarsByNO(downLineModel);
//                                }
//                            }, 1000);//后执行Runnable中的run方法
                        }
                    }
                } else {
                    Toast.makeText(instances, "车牌号码不能为空", Toast
                            .LENGTH_LONG).show();
                }

//                if (adapterCarsList != null && adapterCarsList.size() > 0) {
//                    searChCarsList = new ArrayList<CarsInforModel>();
//                    for (int i = 0; i < adapterCarsList.size(); i++) {
//                        String cno = (adapterCarsList.get(i).getPlateRegion() + adapterCarsList.get
//                                (i).getPlateNO()).toLowerCase();
//                        if (cno.contains(carNO.toLowerCase())) {
//                            searChCarsList.add(adapterCarsList.get(i));
//                        }
//                    }
//                    carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
//                            searChCarsList, CURRENT_CHECK_MODE);
//                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
//                }

                break;
            case R.id.ac_daijian_bt_type2:
//                pop2.showAsDropDown(acDaijianBtType2);
//                //跳转复检拍照界面
//                Intent intent = new Intent(this, RecheckPhotoListActivity.class);
//                startActivity(intent);
                break;
            case R.id.fab:
                if (SharedPreferencesUtils.getAutoRefresh(this)) {
                    getData(0);
                } else {
                    carNO = acDaijianEtSearch2.getText().toString().trim();
                    if (!TextUtils.isEmpty(carNO)) {
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                        downLineModel = new DownLineModel();
                        downLineModel.setType("0");
                        downLineModel.setPlateNO(carNO);
                        searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表
                        for (int i = 0; i < 2; i++) {
                            if (i == 0) {
                                downLineModel.setStatus("0");
                                getDataSearchCarsByNO(downLineModel);
                            } else if (i == 1) {
                                downLineModel.setStatus("1");
                                getDataSearchCarsByNO(downLineModel);
                            }
                        }
                    } else {
                        Toast.makeText(instances, "车牌号码不能为空", Toast
                                .LENGTH_LONG).show();
                    }
                }
                break;
            case R.id.ac_daijian_btn_chongxin_xiaxian:
                //重新下线
                Intent i = new Intent(DaiJianCarsActivity.this, DownLineCarsListActivity.class);
                startActivity(i);
                break;
            case R.id.ac_daijian_btn_buchuan_zhaopian:
                //跳转复检拍照界面,补传照片
                Intent intent = new Intent(this, RecheckPhotoListActivity.class);
                intent.putExtra("Login_name", Login_name);
                intent.putExtra("login_IDNumber", login_IDNumber);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//        Intent intent = new Intent(DaiJianCarsActivity.this, CarDetailsActivity.class);
//        startActivity(intent);
        CarsInforModel carsInforModel = (CarsInforModel) parent.getAdapter().getItem(position);
        UtilsLog.e("carsInforModel=33=" + carsInforModel.toString());
        Intent intent2 = null;
        //检测模式 0:外检  1：路试 2：底盘动态
        if (CHECK_MODE == 0) {
            //外检
//            intent2 = new Intent(DaiJianCarsActivity.this, VehicleDetailsActivity.class);
            intent2 = new Intent(DaiJianCarsActivity.this, CarActivity.class);
//            intent2.putExtra("check_mode",BaseApplication.JIANCE_MODE);
        } else if (CHECK_MODE == 1) {
            //路试
            intent2 = new Intent(DaiJianCarsActivity.this, RoadTestActivity.class);
//            intent2.putExtra("check_mode",BaseApplication.JIANCE_MODE);
        } else if (CHECK_MODE == 6) {
            //地沟
            intent2 = new Intent(DaiJianCarsActivity.this, DiGouActivity.class);
        }else if (CHECK_MODE == 8) {
            //青岛
            intent2 = new Intent(DaiJianCarsActivity.this, QingDaoPhotoActivity.class);
        } else {
            //底盘动态
            intent2 = new Intent(DaiJianCarsActivity.this, DiPanDongTaiActivity.class);
//            intent2 = new Intent(DaiJianCarsActivity.this, VehicleDetailsActivity.class);
//            intent2.putExtra("check_mode",BaseApplication.JIANCE_MODE);
        }
        intent2.putExtra("model_CarsInforModel", carsInforModel);
        intent2.putExtra("check_mode", CHECK_MODE);
        intent2.putExtra("Login_name", Login_name);
        intent2.putExtra("login_IDNumber", login_IDNumber);
        startActivity(intent2);
    }


    private View view2;
    private LinearLayout parent22;
    private PopupWindow pop2 = null;
    private ListView listview_modes;
    private List<String> typeList = new ArrayList<String>();
    MyAccountModeListAdapter myTypeAdapter;

    private void pop_type() {
        for (int i = 0; i < Constants.JIANCE_TYPE.length; i++) {
            typeList.add(i, Constants.JIANCE_TYPE[i]);
        }
        pop2 = new PopupWindow(this);
        view2 = getLayoutInflater().inflate(R.layout.item_pop_type,
                null);
        pop2.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop2.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop2.setBackgroundDrawable(new BitmapDrawable());
        pop2.setFocusable(true);
        pop2.setOutsideTouchable(true);
        pop2.setContentView(view2);
        parent22 = (LinearLayout) view2.findViewById(R.id.ac_daijian_car2_parent);
        listview_modes = (ListView) view2.findViewById(R.id.ac_daijian_car2_listview);
        if (typeList != null && typeList.size() > 0) {
            myTypeAdapter = new MyAccountModeListAdapter(DaiJianCarsActivity.this, typeList);
            listview_modes.setAdapter(myTypeAdapter);
            listview_modes.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int position, long arg3) {
//                Toast.makeText(LoginActivity.this, "====" + strModes.get(position),
//                        Toast.LENGTH_SHORT).show();
                    acDaijianBtType2.setText(typeList.get(position));
                    pop2.dismiss();
                }
            });
        }


        parent22.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop2.dismiss();
            }
        });
    }

    private void getData(int type) {
        if (!TextUtils.isEmpty(SharedPreferencesUtils.getIP(this))) {
            if (CommonUtils.isOnline(this)) {
                if (type == 0) {
//                    getDataCarsListByMode();
                    getDataCarsListByMode_2();
                } else if (type == 1) {

                }
            } else {
                Toast.makeText(this, getResources().getString(R.string.network_error), Toast.LENGTH_LONG)
                        .show();
            }
        } else {
            Toast.makeText(this, "请设置IP与端口号", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
//        acDaijianEtSearch2.setText("");
        UtilsLog.e("是否自动刷新==" + SharedPreferencesUtils.getAutoRefresh(this));
        if (SharedPreferencesUtils.getAutoRefresh(this)) {

            new Thread() {

                @Override
                public void run() {
                    handler.postDelayed(myRunnable, 600);
//                    handler.post(myRunnable);//调用Handler.post方法；
                }
            }.start();


//            this.runOnUiThread(new Runnable() {
//                @Override
//                public void run() {
//                    getData(0);
//                }
//            });
        } else {
            carNO = acDaijianEtSearch2.getText().toString().trim();
            if (!TextUtils.isEmpty(carNO)) {
                CommonUtils.showLoadingDialog(instances, "加载中...");
                downLineModel = new DownLineModel();
                downLineModel.setType("0");
                downLineModel.setPlateNO(carNO);
                searChCarsFilterList = new ArrayList<CarsInforModel>();//查询后过滤的列表
                for (int i = 0; i < 2; i++) {
                    if (i == 0) {
                        downLineModel.setStatus("0");
                        getDataSearchCarsByNO(downLineModel);
                    } else if (i == 1) {
                        downLineModel.setStatus("1");
                        getDataSearchCarsByNO(downLineModel);
                    }
                }
            }
        }
    }


    class MyRunnable implements Runnable {//内部类实现Runnable接口；

        @Override
        public void run() {//还是在Runnable重写的run()方法中更新界面；
//            text.setText("使用Handler更新了界面");
            getData(0);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        instances = null;
        String logStrf = "\n" + "onDestroy-----车辆队列-------" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
    }

    //获取车辆列表
    private void getDataCarsList() {
        if (adapterCarsList != null) {
            adapterCarsList.clear();
        }
        UtilsLog.e("getDataCarsList---url==" + SharedPreferencesUtils.getIP(this) + CARS_LIST_DAI_JIAN);
        OkGo.<String>get(SharedPreferencesUtils.getIP(this) + CARS_LIST_DAI_JIAN).tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
//                        UtilsLog.e("getDataCarsList-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataCarsList-newResult==" + newResult);
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            carsInforModelList = new ArrayList<CarsInforModel>();
                            carsInforModelList = JsonUtil.stringToArray(newResult, CarsInforModel[].class);
                            if (carsInforModelList != null && carsInforModelList.size() > 0) {
                                for (int i = 0; i < carsInforModelList.size(); i++) {
//                                    getDataCarItemsDetails(String.valueOf(carsInforModelList.get(i).getID()
//                                    ), i);
                                    //检测模式 0:外检  1：路试 2：底盘动态
                                    switch (CHECK_MODE) {
                                        case 0:
                                            if (carsInforModelList.get(i).getAppearanceStatus() == 0) {
                                                adapterCarsList.add(carsInforModelList.get(i));
                                            }
                                            break;
                                        case 1:
                                            if (carsInforModelList.get(i).getRoadStatus() == 0) {
                                                adapterCarsList.add(carsInforModelList.get(i));
                                            }
                                            break;
                                        case 2:
                                            if (carsInforModelList.get(i).getDynamicStatus() == 0) {
                                                adapterCarsList.add(carsInforModelList.get(i));
                                            }
                                            break;
                                    }
                                }

                                if (adapterCarsList != null && adapterCarsList.size() > 0) {
//                                    carsInforListAdapter.notifyDataSetChanged();
                                    carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
                                            adapterCarsList, CURRENT_CHECK_MODE);
                                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
//                                    for (int i = 0; i < adapterCarsList.size(); i++) {
//                                        UtilsLog.e("getDataCarsList-carsInforModelList==" +
// adapterCarsList.get(i).toString());
//                                    }
                                } else {
                                    carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
                                            adapterCarsList, CURRENT_CHECK_MODE);
                                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
//                                    carsInforListAdapter.notifyDataSetChanged();
                                }

                            } else {
                                UtilsLog.e("getDataCarsList-result==" + "2222没有数据");
                            }


                        } else {
                            UtilsLog.e("getDataCarsList-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataUsersList-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }


    //获取车辆列表根据选择的检测类型
    private void getDataCarsListByMode() {
        //检测模式 0:外检  F1 1：路试 R1 2：底盘动态 DC
        String car_url = "";
        switch (BaseApplication.JIANCE_MODE) {
            case 0:
                car_url = CAR_LIST_WAIJIAN;
                break;
            case 1:
                car_url = CAR_LIST_LUSHI;
                break;
            case 2:
                car_url = CAR_LIST_DIPAN;
                break;
        }
        if (adapterCarsList != null) {
            adapterCarsList.clear();
        }
        UtilsLog.e("getDataCarsListByMode---url==" + SharedPreferencesUtils.getIP(this) + car_url);
        OkGo.<String>get(SharedPreferencesUtils.getIP(this) + car_url).tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
//                        UtilsLog.e("getDataCarsList-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataCarsListByMode-newResult==" + newResult);
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            carsInforModelList = new ArrayList<CarsInforModel>();
                            carsInforModelList = JsonUtil.stringToArray(newResult, CarsInforModel[].class);
                            if (carsInforModelList != null && carsInforModelList.size() > 0) {
                                for (int i = 0; i < carsInforModelList.size(); i++) {
                                    adapterCarsList.add(carsInforModelList.get(i));
                                }
                            } else {
//                                carsInforListAdapter.notifyDataSetChanged();
                                UtilsLog.e("getDataCarsListByMode-result==" + "2222没有数据");
                            }
                        } else {
//                            carsInforListAdapter.notifyDataSetChanged();
                            UtilsLog.e("getDataCarsListByMode-result==" + "没有数据");
                        }
                        getDataCarsListByMode_2();
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataCarsListByMode-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //获取车辆列表根据选择的检测类型2
    private void getDataCarsListByMode_2() {
        //检测模式 0:外检  F1 1：路试 R1 2：底盘动态 DC
        String car_url = "";
        switch (BaseApplication.JIANCE_MODE) {
            case 8:
                car_url = CAR_LIST_QINGDAO;
                break;
            case 0:
                car_url = CAR_LIST_WAIJIAN;
                break;
            case 1:
                car_url = CAR_LIST_LUSHI;
                break;
            case 2:
                car_url = CAR_LIST_DIPAN;
                break;
            case 6:
                car_url = CAR_LIST_DIGOU;
                break;
        }
        if (adapterCarsList != null) {
            adapterCarsList = new ArrayList<>();
//            adapterCarsList.clear();
        }
        String logStr = "\n" + "待检车辆列表------请求" + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(DaiJianCarsActivity.this) + car_url + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataCarsListByMode-22--url==" + SharedPreferencesUtils.getIP(DaiJianCarsActivity.this) + car_url);
        OkGo.<String>get(SharedPreferencesUtils.getIP(DaiJianCarsActivity.this) + car_url).tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instances, "加载中...");
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        Logger.e(result);
//                        UtilsLog.e("getDataCarsList-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataCarsListByMode-newResult=22=" + newResult);
                        String logStr = "\n" + "待检车辆列表------onSuccess---" + "\n" +
                                "result::" + result + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            carsInforModelList_2 = new ArrayList<CarsInforModel>();
                            carsInforModelList_2 = JsonUtil.stringToArray(newResult, CarsInforModel[].class);
                            if (carsInforModelList_2 != null && carsInforModelList_2.size() > 0) {
                                for (int i = 0; i < carsInforModelList_2.size(); i++) {
                                    adapterCarsList.add(carsInforModelList_2.get(i));
                                }
                            } else {
                                listShequgonggaoBaoxiu.setVisibility(View.GONE);
//                                carsInforListAdapter.notifyDataSetChanged();
                                UtilsLog.e("getDataCarsListByMode-result=22=" + "2222没有数据");
                            }
                        } else {
                            listShequgonggaoBaoxiu.setVisibility(View.GONE);
//                            carsInforListAdapter.notifyDataSetChanged();
                            UtilsLog.e("getDataCarsListByMode-result=22=" + "没有数据");
                        }
                        listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
                        if (adapterCarsList != null && adapterCarsList.size() > 0) {
                            carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
                                    adapterCarsList, CURRENT_CHECK_MODE);
                            listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
                            carsInforListAdapter.notifyDataSetChanged();
                        } else {
                            carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
                                    adapterCarsList, CURRENT_CHECK_MODE);
                            listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
                            carsInforListAdapter.notifyDataSetChanged();
                        }
//                        CommonUtils.hideLoadingDialog(instances);
                        WaitDialog.dismiss();
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        UtilsLog.e("getDataCarsListByMode-onError=22=" + response.body());
                        String logStr = "\n" + "待检车辆列表------onError---" + "\n" +
                                "result::" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //查询 carNO 车牌号码
    private void getDataSearchCars(String carNO) {
        UtilsLog.e("getDataCarsList---url==" + SharedPreferencesUtils.getIP(this) + CARS_LIST_FRONT +
                CARS_LIST_STATUS + CARS_LIST_BEHIND);
        OkGo.<String>get(SharedPreferencesUtils.getIP(this) + CARS_LIST_FRONT + CARS_LIST_STATUS +
                CARS_LIST_BEHIND).tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataCarsList-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataCarsList-newResult==" + newResult);
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            carsInforModelList = JsonUtil.stringToArray(newResult, CarsInforModel[].class);
                            carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
                                    carsInforModelList, CURRENT_CHECK_MODE);
                            listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
                        } else {
                            UtilsLog.e("getDataCarsList-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataUsersList-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }


    //不自动刷新的查询
    //carNO 车牌号码
    private void getDataSearchCarsByNO(DownLineModel downLineModel) {
        Gson gson = new Gson();
        String json_str = gson.toJson(downLineModel);
        UtilsLog.e("getDataSearchCarsByNO---json_str==" + json_str);
        UtilsLog.e("getDataSearchCarsByNO---url==" + SharedPreferencesUtils.getIP(this) + SEARCH_CARS);
        String logStr = "\n" + "待检车辆列表--查询----请求" + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + SEARCH_CARS
                + "\n" + "json" + json_str;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + SEARCH_CARS).tag(this)
                .upJson(json_str)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataSearchCarsByNO-newResult==" + newResult);

                        String logStr = "\n" + "待检车辆列表--查询----请求成功" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + SEARCH_CARS;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            searChCarsList_one = new ArrayList<CarsInforModel>();
                            searChCarsList_one = JsonUtil.stringToArray(newResult, CarsInforModel[]
                                    .class);
                            if (searChCarsList_one != null && searChCarsList_one.size() > 0) {

                                for (int i = 0; i < searChCarsList_one.size(); i++) {
                                    switch (BaseApplication.JIANCE_MODE) {
                                        case 0:
                                            if (searChCarsList_one.get(i).getAppearanceStatus() == 0 ||
                                                    searChCarsList_one.get(i).getAppearanceStatus() ==
                                                            ITEM_MIDDLE_EXIT_CODE) {
                                                searChCarsFilterList.add(searChCarsList_one.get(i));
                                            }
                                            break;
                                        case 1:
                                            if (searChCarsList_one.get(i).getRoadStatus() == 0 ||
                                                    searChCarsList_one.get(i).getRoadStatus() ==
                                                            ITEM_MIDDLE_EXIT_CODE) {
                                                searChCarsFilterList.add(searChCarsList_one.get(i));
                                            }
                                            break;
                                        case 2:
                                            if (searChCarsList_one.get(i).getDynamicStatus() == 0 ||
                                                    searChCarsList_one.get(i).getDynamicStatus() ==
                                                            ITEM_MIDDLE_EXIT_CODE) {
                                                searChCarsFilterList.add(searChCarsList_one.get(i));
                                            }
                                            break;
                                        case 6:
                                            if (!TextUtils.isEmpty(searChCarsList_one.get(i).getC1Status())) {
                                                if (searChCarsList_one.get(i).getC1Status().equals("0")) {
                                                    searChCarsFilterList.add(searChCarsList_one.get(i));
                                                }
                                            }
                                            break;
                                    }
                                }
                                if (searChCarsFilterList != null && searChCarsFilterList.size() > 0) {
                                    String logStrqq = "\n" + "待检车辆列表--查询----searChCarsFilterList" + "\n" +
                                            "result::" + response.body() + "\n" +
                                            "URL::" + SharedPreferencesUtils.getIP(instances) + SEARCH_CARS
                                            + "\n" + "searChCarsFilterList:" + searChCarsFilterList.toString();
                                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrqq.getBytes());

                                    carsInforListAdapter = new CarsInforListAdapter(DaiJianCarsActivity.this,
                                            searChCarsFilterList, CURRENT_CHECK_MODE);
                                    listShequgonggaoBaoxiu.setAdapter(carsInforListAdapter);
                                    listShequgonggaoBaoxiu.setVisibility(View.VISIBLE);
                                } else {
                                    if (searChCarsFilterList != null) {
                                        searChCarsFilterList.clear();
                                    }
                                    listShequgonggaoBaoxiu.setVisibility(View.GONE);
                                }
                            } else {
                                listShequgonggaoBaoxiu.setVisibility(View.GONE);
//                                Toast.makeText(instances, "没有查询到相关车辆", Toast
//                                        .LENGTH_LONG).show();
                            }

                        } else {
                            listShequgonggaoBaoxiu.setVisibility(View.GONE);
                            UtilsLog.e("getDataSearchCarsByNO-result==" + "没有数据");
//                            Toast.makeText(instances, "没有查询到相关车辆", Toast
//                                    .LENGTH_LONG).show();
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataSearchCarsByNO-onError==" + response.body());
                        String logStr = "\n" + "待检车辆列表--查询----请求失败--error" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + CARS_DOWN_LINE;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

}